//
//  MyViewController.m
//  ZHIDOU
//
//  Created by 向礼 on 2018/12/18.
//  Copyright © 2018 向礼. All rights reserved.
//

#import "MyViewController.h"
#import "MyheaderView.h"
#import "MytableViewCell.h"
#import "ZDMyClassViewcontroller.h"

#import "MYOrderViewController.h"
#import "InvitationCodeViewController.h"
#import "MYSetUpViewController.h"
#import "MyCenterViewController.h"
#import "LoginViewController.h"


@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic ,strong)UITableView * tableView;

@property(nonatomic ,strong)MyheaderView *headerView;

@property(nonatomic, strong)NSArray *titleArr;
@end

@implementation MyViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _titleArr = @[@"我的订单",@"邀请码",@"设置"];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setUpViews];
    // Do any additional setup after loading the view.
}

#pragma mark - UI
- (void)setUpViews {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, ZD_screenHeight) style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellEditingStyleNone;
    self.tableView.backgroundColor = ZD_backgroundColor;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"MytableViewCell" bundle:nil] forCellReuseIdentifier:@"MytableViewCell"];
    self.tableView.tableHeaderView = self.headerView;
    [self.view addSubview:self.tableView];
}

- (MyheaderView *)headerView{
    if(_headerView == nil){
        ZD_weakSelf
        _headerView = [[MyheaderView alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, 276*ZD_defaultScale)];
        _headerView.btnBlock = ^(GoVCType goVCType) {
            [weakSelf pushMyClassType:goVCType];
        };
    }
    return _headerView;
}

#pragma mark - 跳转我的课程或者下载或个人中心
-(void)pushMyClassType:(GoVCType)goVcType{
    switch (goVcType) {
        case ClassVC:{
            ZDMyClassViewcontroller *myClassVC = [[ZDMyClassViewcontroller alloc]init];
            myClassVC.VCType = MyClass;
            [self.navigationController pushViewController:myClassVC animated:YES];
            break;
        }
        case DownloadVC:{
            ZDMyClassViewcontroller *myClassVC = [[ZDMyClassViewcontroller alloc]init];
            myClassVC.VCType = MyDownload;
            [self.navigationController pushViewController:myClassVC animated:YES];
            break;
        }
        case MyCenterVC:{
            LoginViewController *login = [[LoginViewController alloc]init];
            //MyCenterViewController *center=[[MyCenterViewController alloc]init];
            [self.navigationController pushViewController:login animated:YES];
            break;
            
        }
    }
   
}

#pragma mark -  TableViewDelegete
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MytableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MytableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleStr = _titleArr[indexPath.section];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, 15)];
    sectionView.backgroundColor = ZD_backgroundColor;
    return sectionView;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        MYOrderViewController *order = [[MYOrderViewController alloc]init];
        [self.navigationController pushViewController:order animated:YES];
    }else if (indexPath.section == 1){
        InvitationCodeViewController *invitation = [[InvitationCodeViewController alloc]init];
        [self.navigationController pushViewController:invitation animated:YES];
    }else if (indexPath.section == 2){
        MYSetUpViewController *setUp =[[MYSetUpViewController alloc]init];
        [self.navigationController pushViewController:setUp animated:YES];
    }
}


@end
